#include <bits/stdc++.h>

#define eb emplace_back
#define in read<int>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)

using namespace std;

using ll = long long;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

const int N = 2e5 + 10;

int n, Q;
int a[N], L[N], R[N], stk[N], top;
ll s[N], ans[N];
vector < tuple < int, int, int, int > > al;

struct BIT {
	ll val[N], tval[N];
	void add(int x, ll y) { ll t = (x - 1) * y; for(; x <= n; x += x & -x) val[x] += y, tval[x] -= t; }
	ll query(int x) { ll t1 = 0, t2 = 0, tx = x; for(; x; x -= x & -x) t1 += val[x], t2 += tval[x]; return t1 * tx + t2; }
} T1, T2;
	
int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, Q = in; rep(i, 1, n) a[i] = in, s[i] = s[i - 1] + a[i];
	rep(i, 1, n) {
		while(top && a[i] > a[stk[top]]) R[stk[top]] = i, top--;
		L[i] = stk[top]; stk[++top] = i; R[i] = n + 1; 
	}
	rep(i, 1, n) if(L[i]) {
		al.eb(0, i, i - L[i], a[L[i]] - a[i]);
		if(R[i] <= n) al.eb(0, R[i], R[i] - L[i], a[i] - a[L[i]]);
	}
	for(auto v : al) T1.add(get<2>(v), get<3>(v));
	rep(i, 1, Q) { int t = in, l = in, r = in; al.eb(i, l - 1, t, -1); al.eb(i, r, t, 1); }
	sort(al.begin(), al.end(), [](auto a, auto b) { return get<1>(a) - get<2>(a) == get<1>(b) - get<2>(b) ? get<0>(a) < get<0>(b) : get<1>(a) - get<2>(a) > get<1>(b) - get<2>(b); });
	for(auto v : al)
		if(get<0>(v) == 0) T1.add(get<2>(v), -get<3>(v)), T2.add(get<1>(v), get<3>(v));
		else ans[get<0>(v)] += get<3>(v) * (s[get<1>(v)] + T1.query(get<2>(v)) + T2.query(get<1>(v)));
	rep(i, 1, Q) printf("%lld\n", ans[i]); return 0;
}
